package com.ychug.gateway.system;


import com.ychug.common.base.ResultAjaxHash;
import com.ychug.framework.web.base.BaseController;
import com.ychug.framework.web.page.TableDataInfo;
import com.ychug.service.system.entity.SysPostEntity;
import com.ychug.service.system.service.ISysPostService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 岗位信息操作处理
 * 
 * @author ruoyi
 */
@Controller
@RequestMapping("/sys/post")
public class SysPostController extends BaseController
{
    private String prefix = "modules/sys/post";

    @Autowired
    private ISysPostService postService;


    @GetMapping()
    public String operlog()
    {
        return prefix + "/viewPost";
    }


    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysPostEntity post)
    {
        startPage();
        List<SysPostEntity> list = postService.selectPostList(post);
        return getDataTable(list);
    }


    @PostMapping("/export")
    @ResponseBody
    public ResultAjaxHash export(SysPostEntity post)
    {
//        List<SysPostEntity> list = postService.selectPostList(post);
//        ExcelUtil<SysPostEntity> utils = new ExcelUtil<SysPostEntity>(SysPostEntity.class);
//        return utils.exportExcel(list, "post");
        return  null;

    }


    @PostMapping("/remove")
    @ResponseBody
    public ResultAjaxHash remove(String ids)
    {
        try
        {
            return toAjax(postService.deletePostByIds(ids));
        }
        catch (Exception e)
        {
            return error(e.getMessage());
        }
    }

    /**
     * 新增岗位
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/addPost";
    }

    /**
     * 新增保存岗位
     */

    @PostMapping("/add")
    @ResponseBody
    public ResultAjaxHash addSave(SysPostEntity post)
    {
        post.setCreateBy("admin");
        return toAjax(postService.insertPost(post));
    }

    /**
     * 修改岗位
     */
    @GetMapping("/edit/{postId}")
    public String edit(@PathVariable("postId") Long postId, ModelMap mmap)
    {
        mmap.put("post", postService.selectPostById(postId));
        return prefix + "/editPost";
    }

    /**
     * 修改保存岗位
     */

    @PostMapping("/edit")
    @ResponseBody
    public ResultAjaxHash editSave(SysPostEntity post)
    {
        post.setUpdateBy("admin");
        return toAjax(postService.updatePost(post));
    }

    /**
     * 校验岗位名称
     */
    @PostMapping("/checkPostNameUnique")
    @ResponseBody
    public String checkPostNameUnique(SysPostEntity post)
    {
        return postService.checkPostNameUnique(post);
    }

    /**
     * 校验岗位编码
     */
    @PostMapping("/checkPostCodeUnique")
    @ResponseBody
    public String checkPostCodeUnique(SysPostEntity post)
    {
        return postService.checkPostCodeUnique(post);
    }
}
